package com.house365.app.analyse.ext.json;


public class Test {

	/**
	 * @param args
	 * @throws JSONException 
	 */
	public static void main(String[] args) throws JSONException {
		
		/**
		 * xml
		 
		 JSONObject jsonobject;
	        String string;

	        jsonobject = XML.toJSONObject("<![CDATA[This is a collection of test patterns and examples for org.json.]]>  Ignore the stuff past the end.  ");
//	        assertEquals("{\"content\":\"This is a collection of test patterns and examples for org.json.\"}", jsonobject.toString());
//	        assertEquals("This is a collection of test patterns and examples for org.json.", jsonobject.getString("content"));
	        System.out.println(jsonobject.toString());
	        string = "<test><blank></blank><empty/></test>";
	        jsonobject = XML.toJSONObject(string);
	        System.out.println(jsonobject.toString());
	        //assertEquals("{\"test\": {\n  \"blank\": \"\",\n  \"empty\": \"\"\n}}", jsonobject.toString(2));
	       // assertEquals("<test><blank/><empty/></test>", XML.toString(jsonobject));
	        * */
		/**
		 * string
		 */
		String json ="{service:{name:register,method:function1,params:[1,2,3]}}";
		
		JSONObject jsonObject = new JSONObject(json);
		System.out.println(jsonObject.toString());
		JSONObject service = jsonObject.getJSONObject("service");
		System.out.println(service.toString());
		if(service.has("params")){

			JSONArray array = service.getJSONArray("params");
			System.out.println(array.length());
			for(int i =0;i<array.length();i++){
				System.out.println(array.get(i));
			}
			
			for(String s : array.toStringArray()){
				System.out.println(s);
			}
		}
		
//		Jsonobjects
//		int[] a = {1,2,3};
//		JSONArray jsonArray = new JSONArray(a);
//		System.out.println(jsonArray.toString());
//		System.out.println(jsonArray.get(1));
	}

}
